import { _squarePoints } from './square.js'

const _peano = (o, r, depth, sweep, startIndex, a) => {
    let points = _squarePoints(o, r, sweep, startIndex, a)
    if (depth === 0) {
        return points
    } else {
        let ps = []
        points.forEach((t, i) => {
            if (i === 0) {
                ps.push(..._peano(t, r / 2, depth - 1, !sweep, startIndex, a))
            }
            else if (i === 1) {
                ps.push(..._peano(t, r / 2, depth - 1, sweep, startIndex, a))
            }
            else if (i === 2) {
                ps.push(..._peano(t, r / 2, depth - 1, sweep, startIndex, a))
            }
            else if (i === 3) {
                ps.push(..._peano(t, r / 2, depth - 1, !sweep, startIndex ? 0 : 2, a))
            }
        })
        return ps
    }
}

export const peanoPoints = (options) => {
    let { o, r, depth, a } = options
    let points = _peano(o, r, depth, false, 0, a)
    return points
}